package logic

import (
	rotatelogs "github.com/lestrrat-go/file-rotatelogs"
	log "github.com/sirupsen/logrus"
	"io"
	"os"
	"path"
)

var Resources *resources

type resources struct {
	CheckLogic CheckLogic
}

func Init(opts ...Option) {
	options := &Options{}
	for _, o := range opts {
		o(options)
	}

	Resources = &resources{
		CheckLogic: newCheckLogic(opts...),
	}
}

func InitLogger(logPath string) {
	r, _ := rotatelogs.New(path.Join(logPath, "%Y%m%d.log"))
	writer := io.MultiWriter(os.Stdout, r)

	log.SetFormatter(&log.JSONFormatter{
		DisableHTMLEscape: true,
		TimestampFormat:   "2006-01-02T15:04:05.999",
		FieldMap: log.FieldMap{
			log.FieldKeyTime: "@timestamp",
		},
	})
	log.SetLevel(log.DebugLevel)
	log.SetOutput(writer)
}
